package com.metaverse.server;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
@ServerEndpoint("/globalWs/{token}")
@Component
public class WebSocketServer {

    /**
     * key: userKye
     * value: GlobalWebsocket  这里你直接存储 session 也是可以的
     */
    private static final Map<String, WebSocketServer> CLIENTS = new ConcurrentHashMap<>();

    private Session session;

    @OnOpen
    public void onOpen(Session session, @PathParam("token") String token) {
        this.session = session;

    }

    @OnMessage
    public void onMessage(Session session, String message) {

    }

    @OnError
    public void onError(Session session, Throwable throwable) {
//        log.error("ws session 发生错误,session key is {}",throwable);
    }

    @OnClose
    public void onClose(Session session) {

    }


}
